package eduservice;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.GlobalConfig;
import com.baomidou.mybatisplus.generator.config.PackageConfig;
import com.baomidou.mybatisplus.generator.config.StrategyConfig;
import com.baomidou.mybatisplus.generator.config.rules.DateType;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
import org.junit.Test;

import java.util.Calendar;


public class CodeGenerator {

    public static void main(String[] args) {
        Calendar c = Calendar.getInstance();
        int month = c.get(Calendar.MONTH)+1;//获取当前月，根据当前月份去修改工资状态
        String mon = month+"月";
        int year = c.get(Calendar.YEAR); //2015，当前年份
        String y = year+"年";
        System.out.println(y+mon);
    }

    @Test
    public void run() {

        // 1、创建代码生成器
        AutoGenerator mpg = new AutoGenerator();

        // 2、全局配置
        GlobalConfig gc = new GlobalConfig();
        String projectPath = System.getProperty("user.dir");
        gc.setOutputDir("D:\\liangyujie\\ideaIU\\oa\\OAMASTER\\services\\LyjConference" + "/src/main/java");
//        gc.setOutputDir("D:\\liangyujie\\ideaIU\\guli_parent1\\service\\service-testt" + "/src/main/java");
        gc.setAuthor("testjava");
        gc.setOpen(false); //生成后是否打开资源管理器
        gc.setFileOverride(true); //重新生成时文件是否覆盖
        //IUserService  ->UserService
        gc.setServiceName("%sService");	//去掉Service接口的首字母I
        gc.setIdType(IdType.ID_WORKER); //主键策略
        gc.setDateType(DateType.ONLY_DATE);//定义生成的实体类中日期类型
        gc.setSwagger2(true);//开启Swagger2模式

        mpg.setGlobalConfig(gc);

        // 3、数据源配置
        DataSourceConfig dsc = new DataSourceConfig();
//        dsc.setUrl("jdbc:mysql://localhost:3306/oa_test?serverTimezone=GMT%2B8");
        dsc.setUrl("jdbc:mysql://rm-2zeha95905bpi5u5tko.mysql.rds.aliyuncs.com:3306/oatest?useUnicode=true&useSSL=false&characterEncoding=utf8");
        dsc.setDriverName("com.mysql.cj.jdbc.Driver");
        dsc.setUsername("root");
        dsc.setPassword("Admin123");
        dsc.setDbType(DbType.MYSQL);
        mpg.setDataSource(dsc);

        // 4、包配置
        PackageConfig pc = new PackageConfig();

        //com.atguigu.eduservice
        pc.setParent("com.bgs");
//        pc.setModuleName("conference"); //模块名

        //com.atguigu.eduservice.controller
        pc.setController("controller");

        //com.atguigu.eduservice.entity
        pc.setEntity("pojo");

        //com.atguigu.eduservice.service
        pc.setService("service");

        //com.atguigu.eduservice.mapper
        pc.setMapper("mapper");
        mpg.setPackageInfo(pc);

        // 5、策略配置-(逆向工程)
        StrategyConfig strategy = new StrategyConfig();
        strategy.setInclude("social_details");         //表名
        strategy.setNaming(NamingStrategy.underline_to_camel);//数据库表映射到实体的命名策略
        strategy.setTablePrefix(pc.getModuleName() + "_"); //生成实体时去掉表前缀

        strategy.setColumnNaming(NamingStrategy.underline_to_camel);//数据库表字段映射到实体的命名策略
        strategy.setEntityLombokModel(true); // lombok 模型 @Accessors(chain = true) setter链式操作

        strategy.setRestControllerStyle(true); //restful api风格控制器
        strategy.setControllerMappingHyphenStyle(true); //url中驼峰转连字符

        mpg.setStrategy(strategy);


        // 6、执行
        mpg.execute();
    }
}
